; SICP, 2.63

(define nil '())

(define (entry tree) (car tree))
(define (left-branch tree) (cadr tree))
(define (right-branch tree) (caddr tree))

(define (make-tree entry left right)
  (list entry left right))
(define (make-tree-s entry)
  (make-tree entry nil nil))

(define (tree->list-1 tree)
  (if (null? tree)
    nil
    (append (tree->list-1 (left-branch tree))
            (cons (entry tree)
                  (tree->list-1 (right-branch tree))))))

(define (tree->list-2 tree)
  (define (copy-to-list tree result-list)
    (if (null? tree)
      result-list
      (copy-to-list (left-branch tree)
                    (cons (entry tree)
                          (copy-to-list (right-branch tree)
                                        result-list)))))
  (copy-to-list tree nil))

(let
  ((T '(7 (3 (1 () ()) (5 () ())) (9 () (11 () ())))))
  (display T)
  (newline)
  (display
    (tree->list-1 T))
  (newline)
  (display
    (tree->list-2 T)))
